-- transform
-- create by chendh
-- 技能: 怪物变身

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 怪物变身
        local classId = para[1];
        local needInit = para[2];
        local resumeHp = para[3];

        -- 先去掉DEBUFF
        PropM.deleteProp(source, "debuff");
        -- 清空负面状态
        CombatStatusM.clearStatusByType(source, COM_STATUS_DEBUFF);
        CombatStatusM.clearStatusByType(source, COM_STATUS_DAMAGE);

        AttribM.setAllDirty(source, true);

        MonsterM.dungeonMonsterTransform(source, classId, { ["layer"] = source.dbase:query("layer")}, needInit == 0);

        -- 刷新属性
        PropM.refresh(source);

        -- 恢复最大血量
        if resumeHp == 1 then
            source.dbase:set("hp", source:getHp());
        end

        -- 计算倒计时会用到此数据
        local grid = DungeonM.getGridByPos(source:getPos());
        grid.openRound = round;

        -- 处于时间停止状态时，变身后的怪物也需要停止
        local prop = PropM.combine(ME.user, "stop_action", 1);
        if prop[3] > 0 then
            local condition = {
                ["end_round"] = prop[4],
            };

            if not SkillM.immunitySkill(ME.user, source, 35) then
                -- 附加施法者的状态
                CombatStatusM.applyStatus(source, "stop_action", condition);
            end
        end

        -- 抛出变身事件
        EventMgr.fire(event.MONSTER_TRANSFORM, {["pos"] = source:getPos(), ["class_id"] = classId, });
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3]) };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
}

